package com.forchange.util

import com.forchange.context.SparkSqlContext
import org.apache.spark.sql.{DataFrame, SparkSession}

import java.util.Properties

/**
 * @Author chencong
 * @Description 读mysql数据
 * @Date 8:27 下午 2021/6/28
 * @Param
 * */
object ReadMysql {
  def main(args: Array[String]): Unit = {
    //环境
    val sparkSqlContext = new SparkSqlContext
    val sparkSession: SparkSession = sparkSqlContext.getSparkSessionBuilder()
    //mysql配置信息
    val properties = new Properties()
    properties.put("user", "root")
    properties.put("password", "123456")

    val url = "jdbc:mysql://192.168.3.100:3306/gmall"

    val tablename = "base_province"

    val df: DataFrame = sparkSession.read.jdbc(url,tablename, properties)

    df.show(100)

  }

}
